// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
const ipc = require('electron').ipcRenderer;
var app = new Vue({
    el: '#app',
    data: {
        message: 'Hello Vue!',
        mapinfo: {
            start: "",
            end: ""
        },
        map: undefined
    },
    created: function () {
        let loadingInstance = this.$loading();
        var map = new AMap.Map('container', {
            resizeEnable: true,
            center: [116.397428, 39.90923],//地图中心点
            zoom: 5 //地图显示的缩放级别
        });
    },
    mounted: function () {

        loadingInstance.close();
        this.map = map;
        /**
     * Created with WebStorm && Sublime Text 3
     * Date: 2015/10/29 14:04
     */
        window.onload = function () {
            map.plugin(["AMap.ToolBar"], function () {
                map.addControl(new AMap.ToolBar());
            });
            if (location.href.indexOf('&guide=1') !== -1) {
                map.setStatus({ scrollWheel: false })
            }
        }
    },
    methods: {
        reset: function () {
            location.reload();
        },
        onSubmit: function () {
            //构造路线导航类
            var driving = new AMap.Driving({
                map: this.map,
            });
            // 根据起终点经纬度规划驾车导航路线
            var startInfo = this.mapinfo.start.split(',');
            var endInfo = this.mapinfo.end.split(',');
            driving.search(new AMap.LngLat(startInfo[0], startInfo[1]), new AMap.LngLat(endInfo[0], endInfo[1]), function (status, result) {
                // result 即是对应的驾车导航信息，相关数据结构文档请参考  https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
                if (status === 'complete') {
                    console.log('绘制驾车路线完成');
                    console.log(result);
                } else {
                    console.log('获取驾车数据失败：' + result)
                }
            });
        }
    }
});
